<?php
class indexControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		if($_SERVER['HTTP_REFERER']=='' || preg_match("/m=login/",$_SERVER['HTTP_REFERER'])){
			$this->onMain();
		}else{
			$this->onList();
		}
	}
	public function onMain(){
			$neworder=M("kcorder")->selectOne(array(
				"where"=>" kcid=".SHOPID." AND  status=0 ",
				"fields"=>" count(order_id) as c"
			));
			$dayorder=M("stat_shoporder_day")->selectRow("shopid=".SHOPID." AND k='kucun' AND kday='".date("Ymd")."' ");
			$monthorder=M("stat_shoporder_month")->selectRow("shopid=".SHOPID." AND k='kucun' AND kmonth='".date("Ym")."' ");
			$allmoney= M("stat_shoporder_month")->getOne(" select sum(money) from ".table('stat_shoporder_month')." WHERE shopid=".SHOPID." AND k='kucun'  ");
			$jsmoney= M("stat_shoporder_day")->getOne(" select sum(money) from ".table('stat_shoporder_day')." WHERE shopid=".SHOPID." AND k='kucun' AND jiesuan=1  ");
			$mon_jsmoney= M("stat_shoporder_day")->getOne(" select sum(money) from ".table('stat_shoporder_day')." WHERE shopid=".SHOPID." AND k='kucun' AND jiesuan=1 AND kday='".date("Ym")."' ");
			$mon_unjsmoney= M("stat_shoporder_day")->getOne(" select sum(money) from ".table('stat_shoporder_day')." WHERE shopid=".SHOPID." AND k='kucun' AND jiesuan=0 AND kday='".date("Ym")."' ");
			 
			$this->smarty->assign(array(
				"neworder"=>$neworder,
				"dayincome"=>$dayorder['money'],
				"dayorder"=>$dayorder,
				"monthorder"=>$monthorder,
				"sushe_num"=>$ssnum,
				"allmoney"=>$allmoney,
				"jsmoney"=>$jsmoney,
				"mon_jsmoney"=>$mon_jsmoney,
				"mon_unjsmoney"=>$mon_unjsmoney, 
				"monthincome"=>$monthorder['money']
			));
		$this->smarty->display("index.html");
	}
	
	public function onNewjs(){
		echo json_encode(array(
			"success"=>1
		));
	}
	
	public function onList(){
		$this->smarty->display("list.html");
	}
	
}

 
?>